/*
 * Copyright (C) 2011, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.model;

import xowl.utils.config.Section;

/**
 *
 * @author Laurent WOUTERS
 */
public abstract class DiagramElement {
    private static final java.util.Random rand = new java.util.Random();
    
    protected String id;
    
    public String getID() { return id; }
    
    public DiagramElement(String id) {
        this.id = id;
    }
    
    public abstract void save(Section section);
    
    public static String generateID(String type) {
        StringBuilder builder = new StringBuilder(type);
        String value = Integer.toHexString(rand.nextInt()).toUpperCase();
        for (int i=0; i!=8-value.length(); i++)
            builder.append('0');
        builder.append(value);
        return builder.toString();
    }
}
